import modules.db
import modules.net.pynet
import modules.transaction
import modules.blockchain 
import modules.appconfig
import threading
import webapp.webapp
import time
from gevent import monkey
from gevent.pywsgi import WSGIServer
"""
windows
#import leveldb
#modules.db.CDb.adddb("chainIndexFile",leveldb.LevelDB(modules.appconfig.CAppconfig.configFromFile['chainIndexFile']))
#modules.db.CDb.adddb("chainStateFile",leveldb.LevelDB(modules.appconfig.CAppconfig.configFromFile['chainStateFile']))
"""
import plyvel
# modules.appconfig.CAppconfig.init()
modules.db.CDb.adddb("chainIndexFile",plyvel.DB(modules.appconfig.CAppconfig.configFromFile['chainIndexFile'],create_if_missing=True))
modules.db.CDb.adddb("chainStateFile",plyvel.DB(modules.appconfig.CAppconfig.configFromFile['chainStateFile'],create_if_missing=True))



modules.blockchain.CBlockchain.init()


def loopMine():
    while True:
        modules.blockchain.CBlockchain.mine()
        # time.sleep(10)
p = threading.Thread(target=loopMine,name="LoopMine")
p.start()
webapp = webapp.webapp.WebApp()
app=modules.net.pynet.CP2pnet.severapp
if __name__ == '__main__':  
    #app.run() 
    http_server = WSGIServer(('127.0.0.1', 5000), app)
    http_server.serve_forever()  
